import 'package:shared_preferences/shared_preferences.dart';

class Storages {
  /*
   * 利用SharedPreferences存储数据
   */
  // 存储string
  Future setString(key, value) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    sharedPreferences.setString(key, value);
  }

  // 存储bool
  Future setBool(key, value) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    sharedPreferences.setBool(key, value);
  }

  // 存储double
  Future setDouble(key, value) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    sharedPreferences.setDouble(key, value);
  }

  // 存储int
  Future setInt(key, value) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    sharedPreferences.setInt(key, value);
  }

  // 存储List<String>
  Future setStringList(key, value) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    sharedPreferences.setStringList(key, value);
  }

  /*
   * 获取存在SharedPreferences中的数据
   */

  Future getStorage(key) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    return sharedPreferences.get(key);
  }

  /*
   * SharedPreferences清空
   */
  Future clear() async {
    SharedPreferences preferences = await SharedPreferences.getInstance();
    preferences.clear();
  }

/*
   * SharedPreferences删除
   */
  Future remove(key) async {
    SharedPreferences preferences = await SharedPreferences.getInstance();
    preferences.remove(key);
  }
}
